package aa;

import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;

import com.attilax.core;
import com.attilax.img.util.OpencvUtil;
import com.attilax.io.filex;

public class javaVideo {
	
	public static void main(String[] args) {
		t2();
		System.out.println("--f");
	}
	
	private static void t2() {
		OpencvUtil.ini();
		 //open camera source  
		VideoCapture capture=new VideoCapture(1);
		  //获取整个帧数
	 //  long totalFrameNumber = capture.get(Highgui.CV_CAP_PROP_f);
		Mat frame=new Mat();
		 boolean stop=false;
		// 遍历每一帧
	    while (true)
	    {
	        // 尝试读取下一帧
         boolean read = capture.read(frame);
         System.out.println(" cap read rzt:"+read);
//		if (!read)
//             break;
         
         Highgui.imwrite("d:\\0clr\\video"+filex.getUUidName()+".jpg", frame);
	//        Highgui..imshow("Extracted Frame",frame);
	        // 引入延迟
	        core.sleep(1000);
	        System.out.println( filex.getUUidName());
	    }
//		if(!vc.isOpened())
//		{
//			
//		}
     //   OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);  
     //   grabber.start();  
		
	}

	public void run3() {
//		CvCapture capture = Highgui.
//				//.cvCreateFileCapture("D:/085402.crf");
//				//CaptureFromCAM
//		
//		//帧率
//		int fps = (int) opencv_highgui.cvGetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FPS);
//		System.out.println("帧率:"+fps);
//		
//		IplImage frame = null;
//		double pos1 = 0;
//		
//		int rootCount = 0;
//
//		while (true) {
//			
//			//读取关键帧
//			frame = opencv_highgui.cvQueryFrame(capture);
//			
//			rootCount = fps;
//			while(rootCount > 0 ){
//				//这一段的目的是跳过每一秒钟的帧数,也就是说fps是帧率(一秒钟有多少帧),在读取一帧后,跳过fps数量的帧就相当于跳过了1秒钟。
//				frame = opencv_highgui.cvQueryFrame(capture);
//				rootCount--;
//			}
//
//			//获取当前帧的位置
//			pos1 = opencv_highgui.cvGetCaptureProperty(capture,opencv_highgui.CV_CAP_PROP_POS_FRAMES);
//			System.out.println(pos1);
//
//			if (null == frame)
//				break;
//			
//			opencv_highgui.cvSaveImage("d:/img/" + pos1 + ".jpg",frame);
//			
//		}
//
//		opencv_highgui.cvReleaseCapture(capture);
	}

}
